package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.common.R;
import com.example.domain.Actor;
import com.example.domain.ActorMovie;
import com.example.mapper.ActorMapper;
import com.example.mapper.ActorMovieMapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api(tags = "演员管理")
@RestController
@RequestMapping("/actor")
public class ActorController {
    @Autowired
    private ActorMapper actorMapper;

    @Autowired
    private ActorMovieMapper actorMovieMapper;

    @GetMapping("/{movieId}")
    public R<List<Actor>> getActors(@PathVariable String movieId){
        ArrayList<String> actorId = new ArrayList<>();
        List<ActorMovie> actorMovies = actorMovieMapper.selectList(new LambdaQueryWrapper<ActorMovie>().eq(ActorMovie::getMovieId, movieId));
        for (ActorMovie actorMovie : actorMovies){
            actorId.add(actorMovie.getActorId());
        }
        List<Actor> actors = actorMapper.selectList(new LambdaQueryWrapper<Actor>().in(Actor::getId, actorId));
        return R.success(actors);
    }



}
